import { createStore } from 'vuex'
import axios from 'axios'
export default createStore({
  state: {
    cartList:[], // 购物车的数据
  },
  mutations: {
    addCart(state,val){
      state.cartList = val;
    },
    del(state){ // 删除选中的方法
      // state.cartList = state.cartList.filter(item => item.ischeck == false)
      state.cartList = state.cartList.filter(item => !item.ischeck)
    }
  },
  actions: {
    getList({commit}){ // 获取购物车的数据
      axios.get('goods.json').then(res => {
        // console.log(res);
        commit('addCart',res.data);
      })
    }
  },
  modules: { // modules 模块化

  }
})
